const { addParkings, getParkings, deleteParkings, getParkingsId, updateParkings } = require('../dao/parkingsDao')

// 获取一个出租方的所有车位
module.exports.getParkings = async function (parking) {
    const data = await getParkings(parking)
    console.log('第二层车位信息获取结果', data)
    if (data.parkings[0].state) {
        return {
            message: '获取车位成功',
            status: 1,
            data
        }
    }
    return {
        message: '获取车位失败',
        status: 0
    }
}

module.exports.addParkings = async function (parking) {
    const data = await addParkings(parking)
    if (data._id) {
        return {
            message: '新增车位成功',
            status: 1
        }

    }
    return {
        message: '新增车位失败',
        status: 0
    }
}

module.exports.deleteParkings = async function (_id) {
    const data = await deleteParkings(_id)
    return data
}

module.exports.getParkingsId = async function (_id) {
    const data = await getParkingsId(_id)
    return {
        message: '一个车位数据获取成功',
        status: 1,
        rows: data
    }
}

module.exports.updateParkings = async function (parkings) {
    const data = await updateParkings(parkings)
    // console.log("111111111nModified", data);
    //输出data里面是{ n: 1, nModified: 1, ok: 1 }所有可以用来做判断
    if (data.nModified === 1) {
        return {
            message: '修改成功',
            status: 1
        }

    } return {
        message: '修改车位失败',
        status: 0
    }
}
